<?php
include_once('CLASS/autoload.php');
require_once ('CLASS/MyPDO.php');
require_once 'CLASS/Article/PreparationREQArticle.php';
require_once 'CLASS/Article/article.class.php';
$PrepREQ = new PreparationREQArticle(new MyPDO());
$page = new page_admin('Modifier-article');
$page->URL(__FILE__);
$ART_ID = $_GET['article'];
$LBrubrique="";
$LBalbum="";
$newarticle = $PrepREQ->selectById($ART_ID);
//print_r($PrepREQ->SelectAllRubrique());
$article = new article (utf8_encode($newarticle['ART_ID']), utf8_encode($newarticle['ART_TITRE']), utf8_encode($newarticle['ART_CONTENU']), utf8_encode($newarticle['ART_ID_DISPOSER']), utf8_encode($newarticle['ART_DATEDEBVALID']), utf8_encode($newarticle['ART_DATEFINVALID']));
//print_r(serialize($article));
foreach ($PrepREQ->SelectAllRubrique() as $options)
{
	if ($newarticle['ART_ID_DISPOSER'] == $options['RUB_ID'])
	{
		$LBrubrique = $LBrubrique.'<option value='.$options['RUB_ID'].' selected>'.$options['RUB_LIBELLE'].'</option>';
	}
	else
	{$LBrubrique = $LBrubrique.'<option value='.$options['RUB_ID'].'>'.$options['RUB_LIBELLE'].'</option>';
	}
}

foreach ($PrepREQ->SelectAllAlbum() as $options)
{
	if ($newarticle['ALB_ID'] == $options['ALB_ID'])
	{
		$LBalbum = $LBalbum.'<option value='.$options['ALB_ID'].'|'.$options['ALB_URL'].' selected>'.$options['ALB_TITRE'].'</option>';
	}
	else
	{
		$LBalbum = $LBalbum.'<option value='.$options['ALB_ID'].'|'.$options['ALB_URL'].'>'.$options['ALB_TITRE'].'</option>';
	}
}

$page->titre = $newarticle['ART_TITRE'];
$page->logo = 'pencil';
$page->contenu = '
	<div class="col-lg-9 main-chart">
		<div class="col-md-12">
			<div class="content-panel">
				<h4><i class="fa fa-pencil"></i> Modifier Article</h4>
				<div class="form-panel">
					<form class="form-horizontal style-form" method="POST" action="CLASS/Administrateur/receptionform.php">
						<h4><i class="fa fa-angle-right"></i> Informations</h4><hr>
						<div class="form-group">
							<label class="col-sm-2 col-sm-2 control-label">Titre</label>
							<div class="col-sm-10">
								<input class="form-control" id="titrearticle" name="Titre" type="text" value="'.utf8_encode($newarticle['ART_TITRE']).'">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 col-sm-2 control-label">Rubrique</label>
							<div class="col-sm-10">
								<select id="rubriquearticle" class="form-control" name="Rubrique">
									'.utf8_encode($LBrubrique).'
								</select>
							</div>
						</div>
					<script>
					$(function() {
 						$( "#datefin" ).datepicker();	
 						$( "#datedebut" ).datepicker();
									});
					</script>
						<div class="form-group">
							<label class="col-sm-2 col-sm-2 control-label">Date de debut</label>
							<div class="col-sm-10">
								<input class="form-control" id="datedebut" name="datedebut" type="text" value="'.$article->getDatedebut().'">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 col-sm-2 control-label">Date de Fin</label>
							<div class="col-sm-10">
								<input class="form-control" id="datefin" name="datefin" type="text" value="'.$article->getDatefin().'">		
							</div>
						</div>
						<form id="ckeditor-form">
							<textarea name="editor1" id="contenuarticle" rows="10" cols="80">
								'.utf8_encode($newarticle['ART_CONTENU']).'
							</textarea>
							<script>
								CKEDITOR.replace( "editor1" );
							</script>
						</form>
					</div>
				<input id="ID" type="hidden" value='.$newarticle['ART_ID'].'>
				<span style="padding-left:62%;">
				<button id="enregistrer" type="button" class="btn btn-info col-xs-push-8"><i class="fa fa-floppy-o"></i> Enregistrer</button>
				<button  type="button" class="btn btn-success col-xs-push-8"><i class="fa fa-check"></i> Valider</button>
				<button  type="button" class="btn btn-danger col-xs-push-8"><i class="fa fa-remove"></i> Annuler</button>
				</span>
				</div>
			</div>
		</div>
			<div class="col-lg-3 ds">	
				<h3>PHOTO</h3><br>
					<img class="col-lg-12 content-panel" src="assets/img/PhotoProfil/nophoto.jpg">
					<form class="col-lg-12" method="post" action="CLASS/Article/modification.php" enctype="multipart/form-data">
					<br><input type="file" name="imagearticle" id="imagearticle" />
						<input type="hidden" value='.base64_encode(serialize($article)).' name="article">
						<br><select name="AlbumImageArticle" class="form-control">
						'.$LBalbum.'
						</select>
					<br><button id="envoyerimage" type="submit" class="btn btn-default centered">Envoyer</button>
					</form>
			</div>
		</div>
								';
$page->affiche();
?>